package {
     import flash.display.Sprite;
     import flash.display.BitmapData;
     import flash.display.Bitmap;
     import flash.filters.ConvolutionFilter;
     import flash.geom.Rectangle;
     import flash.geom.Point;
     import flash.events.MouseEvent;
 
    public class ConvolutionClampExample3 extends Sprite {
        private var largeBoxWidth:Number = 100;
         private var largeBoxHeight:Number = 100;
         private var largeBoxData:BitmapData = new BitmapData(largeBoxWidth, largeBoxWidth, true, 0xCC00FF00);
 
  
        public function ConvolutionClampExample3() {
            var largeBox:Bitmap = new Bitmap(largeBoxData);
            var mySprite:Sprite = new Sprite();
 
            this.addChild(mySprite);
            mySprite.addChild(largeBox);
             
            this.addEventListener(MouseEvent.CLICK, clickHandler);      
        }
         
        private function clickHandler(e:MouseEvent):void {
            var smallBoxWidth:Number = largeBoxWidth / 2;
            var smallBoxHeight:Number = largeBoxHeight / 2;
            var smallBoxData:BitmapData = new BitmapData(smallBoxWidth, smallBoxWidth, true, 0xCC0000FF);
 
            var clamp:Boolean = false;
            var clampColor:Number = 0xFF0000;
            var clampAlpha:Number = 1;
         
            var bias:Number = 0;
            var preserveAlpha:Boolean = false;
         
            var matrixCols:Number = 3;
            var matrixRows:Number = 3;
            var matrix:Array = [ 1,1,1,
                                 1,1,1,
                                 1,1,1 ];
 
            var myfilter:ConvolutionFilter = new ConvolutionFilter(matrixCols, matrixRows, matrix, 
                                matrix.length, bias, preserveAlpha, clamp, clampColor, clampAlpha);
 
  
            largeBoxData.applyFilter(smallBoxData,
                                  new Rectangle(0,0, largeBoxWidth, largeBoxHeight),
                                  new Point(0,0),
                                  myfilter);
        }
    }
}
